package com.gcstorage.tvdev.net;

import android.webkit.WebView;

import com.google.gson.JsonElement;

import org.apache.commons.text.StringEscapeUtils;


/**
 * H5请求回调
 * created by Sanpark on 2020-09-08 09:42
 */
public class H5RxObserver extends RxObserver {
    private final String jsMethod;
    private final WebView webView;

    public H5RxObserver(String jsMethod, WebView webView) {
        this.jsMethod = jsMethod;
        this.webView = webView;
    }

    @Override
    public void onSuccess(JsonElement t) {
    }

    @Override
    public void onH5Success(JsonElement t) {
        super.onH5Success(t);
        webView.loadUrl("javascript:" + jsMethod + "('" + StringEscapeUtils.escapeJson(t.toString()) + "')");
    }
}
